function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
    return (false);
}

$(() => {
    let title = decodeURI(getQueryVariable("title"));
    let description = decodeURI(getQueryVariable("description"));
    let content = decodeURI(getQueryVariable("content"));
    if (title === 'false') {
        document.querySelector('#right > form > div:nth-child(4) > div > button:nth-child(1)').innerHTML = '创建'
    } else {
        document.querySelector('#right > form > div:nth-child(4) > div > button:nth-child(1)').innerHTML = '修改';
        document.querySelector('#right > form > div:nth-child(1) > div > input').value = title;
        document.querySelector('#right > form > div:nth-child(2) > div > input').value = description;
        document.querySelector('#right > form > div.layui-form-item.layui-form-text > div > textarea').value = content;
    }
    document.querySelector('#right > form').onsubmit = function () {
        console.log(this);
        let title = document.querySelector('#right > form > div:nth-child(1) > div > input').value.trim();
        let description = document.querySelector('#right > form > div:nth-child(2) > div > input').value.trim();
        let content =document.querySelector('#right > form > div.layui-form-item.layui-form-text > div > textarea').value.trim();
        this.action = './index.html?title=' + title + '&description=' + description+'&content='+content;
    }
});